package logic

import (
	"context"
	"login-guard/loginrpc/loginrpcclient"

	"login-guard/api/internal/svc"
	"login-guard/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginsLogic {
	return &LoginsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginsLogic) Logins(req *types.LoginsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	login, err := l.svcCtx.LoginRpc.Logins(l.ctx, &loginrpcclient.LoginsRequest{
		Username: req.Username,
		Password: req.Password,
		SendSms:  req.SendSms,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "登陆成功",
		Data:    login,
		Code:    200,
	}, nil
}
